<template>
  <div o-Container>
    <!-- created: create, -->
    <o-list v-bind:source="list.contract" v-bind="{ searched: search, exported: output }">
      <template slot="config" slot-scope="scope">
        <div class="img_box">
          <img @click="modify(scope.data.row, '2')" src="/static/skin/default/MCS/AIGC/Inventory/images/chakan.png"
            alt="" />
          <img v-if="isCompany == 1" @click="modify(scope.data.row, '1')"
            :class="{ disable: isDisabled(scope.data.row) }"
            src="/static/skin/default/MCS/AIGC/Inventory/images/tongguo.png" alt="" />
          <img v-if="isCompany == 1" @click="modify(scope.data.row, '0')"
            :class="{ disable: isDisabled(scope.data.row) }"
            src="/static/skin/default/MCS/AIGC/Inventory/images/bohui.png" alt="" />
        </div>
      </template>
    </o-list>

    <auditDrawer ref="auditDrawer" :compileData="compileData" :compileId="compileData.ID" :btnType="btnType"
      @amendType="amendType" @refresh="refresh"></auditDrawer>
  </div>
</template>

<script>
import auditDrawer from "../Components/auditDrawer.vue";
export default {
  name:
    "mms_platform_company_list" /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */,
  components: {
    auditDrawer
  },
  data() {
    return {
      octopus: this.$parent.octopus,
      list: {
        contract: {
          data: {
            id: 1195, // 菜单表的八爪鱼ID
            cellData: [
              { name: "Address", show: false }, // 使用地址
              { name: "Name", searchKey: "LIKE", width: 400 }, // 权益标题
              { name: "ProductFlagListName", width: 180 }, // 产品类型
              { name: "TypeID", show: false }, // 是否为权益礼包
              { name: "TypeIDName" }, // 是否为权益礼包
              { name: "CompanyID", show: false }, // 提交企业
              { name: "CompanyName" }, // 提交企业
              { name: "ProductCode" }, // 合同编号
              { name: "InventoryQuantity" }, // 库存数量(份)
              { name: "SalePrice" }, // 市场价格
              { name: "CostPrice" }, // 平台价格
              { name: "EquityServiceRate", show: false }, // 权益平台服务费
              { name: "PlatformServiceRate", show: false }, // 平台服务费
              { name: "Integral" }, // 让利积分
              // {name: "PlatformServicePrice", show: false},	// 平台结算价格（元）
              // {name: "EquityServicePrice", show: false},	// 小程序结算价格（元）
              { name: "StatusName" }, // 审核状态
              { name: "CreateTime", width: 150 }, // 提交时间
              { name: "IsOpenSale", show: false }, // 是否允许在其他国企平台售卖
              { name: "IsRefund", show: false }, // 是否允许退款
              { name: "EffectiveTime", show: false }, // 生效时间
              { name: "MainPicturePath", show: false }, // 主图
              { name: "ProductFlagList", show: false }, // 产品类型
              { name: "ID", show: false }, // ID
              { name: "ProductID", show: false }, // 产品ID
              { name: "ProductName", show: false }, // 产品ID
              { name: "ExpireTime", show: false }, // 过期时间
              { name: "MinimumQuantity", show: false }, // 起售数量
              { name: "EquityFlagListName", show: false }, // 权益标签
              { name: "EquityList", show: false }, // 权益集合
              // {name: "ProductList", show: false},	// 产品列表
              { name: "TransferRuleIDName", show: false }, // 采购公司限制
              { name: "EquityFlagList", show: false }, // 权益标签
              { name: "Status", show: false, filterKey: '=', filterValue: '2' }, // 审核状态
              { name: "SecondaryPicturePath", show: false }, // 副图
              { name: "TransferRuleID", show: false }, // 采购公司限制
              { name: "UsersCount", show: false }, // 使用人数
              { name: "FilePath", show: false }, // 合同附件路径
              { name: "Description", show: false }, // 权益详情
              { name: "UseRuleDescription", show: false }, // 使用规则详情
              { name: "IsRefundAudit", show: false } // 退款是否需要审核
            ],
            paramData: {}
          },
          configWidth: 90,
          showNumber: true
        }
      },
      panel: {
        visible: false
      },
      repetition: true,
      compileData: {},
      btnType: 2,
      isCompany: 1
    };
  },
  created() {
    this.init();
  },
  methods: {
    // create: function () {//弹出创建页面
    //   this.item.contract.data.value = null;
    //   this.item.contract.control.load();
    //   this.panel.visible = true;
    // },
    // 修改状态
    init() {
      const data = this.list.contract.data;
      let company = this.octopus.passport.authorization.company;
      data.paramData.CompanyID = company == 1 ? "NULL" : company;
      this.isCompany = company;
      this.list.contract.configWidth = company == 1 ? 90 : 35;
    },
    amendType(item) {
      let this_ = this;
      this.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          type: "UPDATE",
          id: 748,
          cellData: [
            { name: "Status", defaultValue: item.type } // 权益状态（保存未提交（草稿箱）、已提交/待审核、审核通过、审核未通过、未启用，启用、已售完、到期）
          ],
          value: this_.compileData.ID
        },
        function (data) {
          if (data.status.code == 200) {
            this_.$refs.auditDrawer.drawerClose();
            this_.list.contract.control.load();
          } else {
            this_.$refs.auditDrawer.drawerClose();
            this_.list.contract.control.load();
            o.octopus.tips.error(data);
          }
        }
      );
    },
    output: function (data) {
      this.octopus.tips.success("下载完成。");
    },
    search: function (cell) { },
    modify(row, type) {
      //修改页面
      if (type == 2 || !this.isDisabled(row)) {
        this.compileData = {};
        this.btnType = type;
        this.compileData = row;
        this.$nextTick(() => {
          this.$refs.auditDrawer.drawerOp();
        });
      }
    },
    view: function (row) {
      alert("view key: " + JSON.stringify(row));
    },
    save: function (data) {
      // 保存
      this.octopus.tips.success(data);
      // 刷新list
      this.list.contract.control.load();
      this.back();
    },
    back: function () {
      this.panel.visible = false;
    },
    refresh() {
      this.list.contract.control.load();
    },

    isDisabled(row) {
      return row.Status == 5 || row.Status == 4;
    }
  },
  props: ["oData"]
};
</script>
<style scoped>
.el-message-box {
  background-color: #fff !important;
}

.btnclass {
  margin-left: 4px;
  border: none;
  padding: 2px 4px;
  border-radius: 2px;
  white-space: nowrap;
}

.info {
  background-color: #f78c51;
  color: #fff;
}

.img_box {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.img_box img {
  width: 25px;
  cursor: pointer;
}

.img_box .disable {
  cursor: not-allowed;
  opacity: 0.5;
}
</style>
